package com.example.dubbo.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.damain.R;
import com.example.common.damain.Users;
import com.example.common.service.UserService;
import com.example.dubbo.mapper.UserMappers;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author renyitong
 * @description: TODO
 * @date 2023年07月11日
 */
@DubboService
@Slf4j
@Service
public class UserServiceImpl extends ServiceImpl<UserMappers, Users> implements UserService {

    @Override
    public R selectList(Integer sex, Integer pageNo, Integer pageSize) {
        Page<Users> page = new Page<>(pageNo, pageSize);
        LambdaQueryWrapper<Users> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(!Objects.isNull(sex), Users::getSex, sex);
        lambdaQueryWrapper.orderByDesc(Users::getCreateTime);
        Page<Users> pagesUser = this.page(page, lambdaQueryWrapper);
        R result = R.ok(pagesUser);
        return result;
    }

}
